package com.rongji.dfish.hello.index.view;

import org.springframework.stereotype.Component;

import com.rongji.dfish.hello.pub.view.CommonView;
import com.rongji.dfish.ui.helper.TabPanel;
import com.rongji.dfish.ui.layout.HorizontalLayout;
import com.rongji.dfish.ui.layout.VerticalLayout;
import com.rongji.dfish.ui.layout.View;
import com.rongji.dfish.ui.widget.Button;
import com.rongji.dfish.ui.widget.DialogTemplate;
import com.rongji.dfish.ui.widget.Html;
import com.rongji.dfish.ui.widget.TemplateTitle;
import com.rongji.dfish.ui.widget.TemplateView;

@Component
public class IndexView extends CommonView {

	/**
	 * 对话框模板-默认对话框,一般都是使用这个对话框
	 * 
	 * @return
	 */
	public static DialogTemplate getStdTemplate() {
		DialogTemplate std = new DialogTemplate().setCls("dlg-std");

		VerticalLayout vp = new VerticalLayout(null);
		std.setNode(vp);
		HorizontalLayout head = new HorizontalLayout(null).setCls("dlg-std-head");
		vp.add(head, "40");
		head.add(new TemplateTitle(null).setCls("dlg-std-title").setWmin(10).setOn(Html.EVENT_DBLCLICK,
				"$.dialog(this).max(this)"), "*");
		head.add(new Html(null, "<i class=ico-dlg-max></i>").setCls("dlg-max").setAlign("center").setValign("middle")
				.setOn(Html.EVENT_CLICK, "$.dialog(this).max(this)"), "40");
		head.add(new Html(null, "<i class=ico-dlg-close></i>").setCls("dlg-close").setAlign("center")
				.setValign("middle").setOn(Html.EVENT_CLICK, "$.close(this);"), "40");

		TemplateView cont = new TemplateView(null);
		vp.add(cont, "*");
		return std;
	}

	/**
	 * 对话框模板-表单对话框,表单有变动时关闭有进行表单是否保存的提示
	 * 
	 * @return
	 */
	public static DialogTemplate getFormTemplate() {
		DialogTemplate std = new DialogTemplate().setCls("dlg-std");

		VerticalLayout vp = new VerticalLayout(null);
		std.setNode(vp);
		HorizontalLayout head = new HorizontalLayout(null).setCls("dlg-std-head");
		vp.add(head, "40");
		head.add(new TemplateTitle(null).setCls("dlg-std-title").setWmin(10).setOn(Html.EVENT_DBLCLICK,
				"$.dialog(this).max(this)"), "*");
		head.add(new Html(null, "<i class=ico-dlg-max></i>").setCls("dlg-max").setAlign("center").setValign("middle")
				.setOn(Html.EVENT_CLICK, "$.dialog(this).max(this)"), "40");
		head.add(
				new Html(null, "<i class=ico-dlg-close></i>").setCls("dlg-close").setAlign("center").setValign("middle")
						.setOn(Html.EVENT_CLICK,
								"var dlg=$.dialog(this);if(!dlg.contentView.isModified()){pub.dialogClose(dlg);}else{"
										+ "$.dialog(this).contentView.cmd({type:'confirm',text:'您有内容尚未保存，确认关闭窗口吗？',"
										+ "yes:function(){pub.dialogClose(dlg);}});" + "}"),
				"40");

		TemplateView cont = new TemplateView(null);
		vp.add(cont, "*");
		return std;
	}

	/**
	 * 对话框模板-信息提示框(alert)
	 * 
	 * @return
	 */
	public static DialogTemplate getAlertTemplate() {
		DialogTemplate std = new DialogTemplate().setId("alert").setCls("dlg-std");

		VerticalLayout vp = new VerticalLayout(null);
		std.setNode(vp);
		HorizontalLayout head = new HorizontalLayout(null).setCls("dlg-std-head");
		vp.add(head, "40");
		head.add(new TemplateTitle(null).setCls("dlg-std-title").setWmin(10), "*");
		head.add(new Html(null, "<i class=ico-dlg-close></i>").setCls("dlg-close").setAlign("center")
				.setValign("middle").setOn(Html.EVENT_CLICK, "$.dialog(this).close()"), "40");

		TemplateView cont = new TemplateView(null);
		vp.add(cont, "*");
		return std;
	}

	/**
	 * 对话框模板-信息提示框(带指向的)
	 * 
	 * @return
	 */
	public static DialogTemplate getProngTemplate() {
		DialogTemplate std = new DialogTemplate().setId("prong").setCls("dlg-prong").setIndent(-10);
		VerticalLayout vp = new VerticalLayout(null);
		std.setNode(vp);
		vp.setAftercontent("<div class=dlg-prong-arrow-out></div><div class=dlg-prong-arrow-in></div>");

		HorizontalLayout head = new HorizontalLayout(null).setCls("dlg-prong-head");
		vp.add(head, "36");
		head.add(new TemplateTitle(null).setCls("dlg-prong-title"), "*");
		head.add(new Html(null, "<i onclick=$.close(this) class='dlg-close'>&times;</i><i class=f-vi></i>")
				.setAlign(Html.ALIGN_CENTER).setValign(Html.VALIGN_MIDDLE), "40");

		TemplateView cont = new TemplateView(null);
		vp.add(cont, "*");
		return std;
	}

	public View buildIndexView() {
		View view = new View();

		VerticalLayout root = new VerticalLayout("root");
		view.add(root);

		TabPanel tab = new TabPanel("tab");
		root.add(tab);
		tab.getTabBar().setHeight(50);

		tab.add(new Html("欢迎使用DFish开发框架，这是系统的首页。"), new Button("首页"));
		tab.add(new View().setSrc("user/index"), new Button("人员管理"));

		view.addTemplate("std", getStdTemplate());
		view.addTemplate("form", getFormTemplate());
		view.addTemplate("alert", getAlertTemplate());
		view.addTemplate("prong", getProngTemplate());

		return view;
	}

}
